//寻找旋转排序数组中的最小值
class Solution {
public:
    int findMin(vector<int>& nums) {
        int left = 0 , n = nums.size() , right = n-1;
        while(left < right)
        {
            int mid = left + (right - left)/2;
            if(nums[mid] >= nums[0]) left = mid + 1;
            else right = mid;
        }
        return nums[0] < nums[left] ? nums[0] : nums[left];
    }
};

//点名(找出0-n中缺失的数字，有序)
class Solution {
public:
    int takeAttendance(vector<int>& records) {
        int left = 0 , right = records.size() - 1;
        while(left < right)
        {
            int mid = left + (right - left)/2;
            if(records[mid] == mid) left = mid + 1;
            else right = mid;
        }
        if(left == records[left]) return left+1;
        return left;
    }
};

//寻找数组的中心下标
class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int n = nums.size();
        vector<int> dp(n+1);
        for(int i = 1 ; i <= n ; ++i)
        {
            dp[i] = dp[i-1] + nums[i-1];
        }
        for(size_t i = 1 ; i <= n ; ++i)
        {

            if(dp[i-1] == dp[n] - dp[i])return i-1;
        }
        return -1;
    }
};

//[模板]一维前缀和
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n , q;
    cin >> n >> q;
    vector<int> arr(n+1);
    for(size_t i = 1 ; i <= n ; ++i)
    {
        cin >> arr[i];
    }
    //dp预处理以i位置为结尾的前缀和
    vector<long long> dp(n+1);
    for(size_t i = 1 ; i <= n ; ++i)
    {
        dp[i] = dp[i-1] + arr[i];
    }
    int l , r;
    while(q--)
    {
        cin >> l >> r;
        cout << dp[r] - dp[l-1] << endl;
    }
    return 0;
}


//[模板]二维前缀和
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> arr(n + 1, vector<int>(m + 1));
    for (size_t i = 1; i <= n; ++i)
    {
        for (size_t j = 1; j <= m; ++j)
        {
            cin >> arr[i][j];
        }
    }

    //dp预处理前缀和矩阵
    vector<vector<long long>> dp(n + 1, vector<long long>(m + 1));
    for (size_t i = 1; i <= n; ++i)
    {
        for (size_t j = 1; j <= m; ++j)
        {
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i-1][j-1] + arr[i][j];
        }
    }

    //开始查询
    int x1, x2, y1, y2;
    while (q--)
    {
        cin >> x1 >> y1 >> x2 >> y2;
        std::cout << dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1] << std::endl;
    }
}

//寻找数组的中心下标
class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int n = nums.size();
        vector<int> dp(n+1);
        for(int i = 1 ; i <= n ; ++i)
        {
            dp[i] = dp[i-1] + nums[i-1];
        }
        for(size_t i = 1 ; i <= n ; ++i)
        {

            if(dp[i-1] == dp[n] - dp[i])return i-1;
        }
        return -1;
    }
};









